package com.kevin.learn.d.代理对象.b.动态代理;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyFactory {
    
    private Object target;

    public ProxyFactory(Object target) {
        this.target = target;
    }
    
    
    public Object getProxyInstance(){
        
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("动态准备。。。 ");
                        Object invoke = method.invoke(target, args);
                        System.out.println("动态结束。。。");
                        return invoke;
                    }
                }
        );
    }
}
